<template>
	<view class="content">
		<u-button type="primary" text="充值" @click="goRecharge"></u-button>
		<u-button type="primary" text="会话" @click="goChat"></u-button>
	</view>
</template>

<script>
	import {
		chatSaveApi
	} from '@/api/chat.js'
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				chatId: undefined,
			}
		},
		onLoad() {
			this.createChat()
		},
		computed: {
			...mapState({
				userId: state => state.user.userInfo.userId ? state.user.userInfo.userId : state.user.userInfo.id
			})
		},
		methods: {
			async createChat() {
				let res = await chatSaveApi({
					userId: this.userId,
					type: 1
				})
				this.chatId = res.data.chatId
			},
			goRecharge() {
				uni.navigateTo({
					url: '/subPackages/userConfig/recharge'
				})
			},
			goChat() {
				uni.navigateTo({
					url: `/subPackages/commonPage/chat?chatId=${this.chatId}`
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>